package com.demo4;

import com.demo4.exception.ArgementErrorException;
import com.demo4.exception.MinusArgementException;

import java.util.Scanner;

/**
 * 椭圆
 *
 * @author J.L.Zhou
 * jlzhou.top 版权所有
 */
public class Ellipse extends AbstractShape {
  /**
   * 宽
   */
  private float a;
  /**
   * 高
   */
  private float b;


  public Ellipse() {
    super("椭圆形");
  }

  protected Ellipse(String name) {
    super(name);
  }


  @Override
  public void inputBaseInfo(Scanner sc)throws MinusArgementException, ArgementErrorException {
    System.out.println("输入" + getName() + "的最长半径: ");
    a = sc.nextFloat();
    if (a <= 0 ) {
      throw new MinusArgementException();
    }
    System.out.println("输入" + getName() + "的最短半径: ");
    b = sc.nextFloat();

    if (b <= 0) {
			throw new MinusArgementException();
    }

    if(a==b){
      throw new ArgementErrorException("您输入的其实是一个圆");
    }

    if (b > a) {
      float temp = a;
      a = b;
      b = temp;
    }
  }

  @Override
  public float calcArea() {
    return (float) (Math.PI * a * b);
  }

  @Override
  public float caclPerimeter() {
    return (float) (2 * Math.PI * b + 4 * (a - b));
  }


  @Override
  public String getBaseInfo() {
    return String.format("半径：%.2f，%.2f", a, b);
  }


  public float getA() {
    return a;
  }


  public void setA(float a) {
    this.a = a;
  }


  public float getB() {
    return b;
  }


  public void setB(float b) {
    this.b = b;
  }


  public static void main(String[] args) {
    Ellipse rectangle = new Ellipse();
    rectangle.input(new Scanner(System.in));
    rectangle.show();
  }

}
